clear all
set more off

local save_figures_flag=1

use atus_early, clear

local age_min=16
local age_max=64

keep if age>=`age_min' & age<=`age_max'
keep if student==0

order dataset male
sort dataset male



by dataset male: egen by_sex_work=wtmean(work), weight(weight)
by dataset: egen both_sex_work=wtmean(work), weight(weight)
by dataset male: egen by_sex_nonmarketwork=wtmean(nonmarket_work), weight(weight)
by dataset: egen both_sex_nonmarketwork=wtmean(nonmarket_work), weight(weight)
by dataset male: egen by_sex_childcare=wtmean(child_care_full-child_care_play), weight(weight)
by dataset: egen both_sex_childcare=wtmean(child_care_full-child_care_play), weight(weight)
by dataset male: egen by_sex_leisure=wtmean(leisure_1+child_care_play), weight(weight)
by dataset: egen both_sex_leisure=wtmean(leisure_1+child_care_play), weight(weight)

quietly by dataset male: gen dup = cond(_N==1,0,_n)
drop if dup>1



keep dataset male by_* both_*

rename dataset year

save temp_65_03, replace 



use atus_late.dta, clear 
keep if age>=`age_min' & age<=`age_max'

rename tuyear year

order year male
sort year male

keep if student==0


by year male: egen by_sex_work=wtmean(work/60*365/52), weight(weight)
by year: egen both_sex_work=wtmean(work/60*365/52), weight(weight)
by year male: egen by_sex_nonmarketwork=wtmean(nonmarket_work/60*365/52), weight(weight)
by year: egen both_sex_nonmarketwork=wtmean(nonmarket_work/60*365/52), weight(weight)
by year male: egen by_sex_childcare=wtmean((child_care_full-child_care_play)/60*365/52), weight(weight)
by year: egen both_sex_childcare=wtmean((child_care_full-child_care_play)/60*365/52), weight(weight)
by year male: egen by_sex_leisure=wtmean((leisure_1+child_care_play)/60*365/52), weight(weight)
by year: egen both_sex_leisure=wtmean((leisure_1+child_care_play)/60*365/52), weight(weight)

quietly by year male: gen dup = cond(_N==1,0,_n)
drop if dup>1



keep year male by_* both_*

append using temp_65_03
erase temp_65_03.dta

sort year male

collapse (mean) by_* both_*, by(year male) 

gen by_sex_totalwork=by_sex_work+by_sex_nonmarketwork+by_sex_childcare
gen both_sex_totalwork=both_sex_work+both_sex_nonmarketwork+both_sex_childcare

gen by_sex_leisure_broad=16*7-by_sex_totalwork /*8 hours for basic sleep*/
gen both_sex_leisure_broad=16*7-both_sex_totalwork /*8 hours for basic sleep*/


replace by_sex_work=by_sex_work*52
replace by_sex_totalwork=by_sex_totalwork*52
replace by_sex_leisure_broad=by_sex_leisure_broad*52
replace both_sex_work=both_sex_work*52
replace both_sex_totalwork=both_sex_totalwork*52
replace both_sex_leisure_broad=both_sex_leisure_broad*52

twoway (connected by_sex_work by_sex_totalwork by_sex_leisure_broad year if male==1,/*
*/lpattern(solid dash dash_dot shortdash solid longdash solid solid) /*
*/msymbol(x o s p s p x o) msize(large medium small)), /*
*/leg(label (1 "Market work") label(2 "Total work") label(3 "Leisure") position(7) ring(0) cols(1)) xlabel(1960[10]2020) ylabel(780[520]3380) xtitle("")/*
*/bgcolor(white) graphregion(color(white)) plotregion(lcolor(black) lwidth(medthin)) xlabel(,grid nogextend gmax) ytitle("Annual hours") ylabel(,grid nogextend) ysize(4)
if `save_figures_flag'==1 {
	graph export "../figures/atus_male.png", as(png) replace
	graph export "../figures/atus_male.eps", as(eps) replace
}
*black and white
twoway (connected by_sex_work by_sex_totalwork by_sex_leisure_broad year if male==1,/*
*/lpattern(solid dash dash_dot shortdash solid longdash solid solid) /*
*/msymbol(x o s p s p x o) msize(large medium small)), /*
*/leg(label (1 "Market work") label(2 "Total work") label(3 "Leisure") position(7) ring(0) cols(1)) xlabel(1960[10]2020) ylabel(780[520]3380) xtitle("")/*
*/bgcolor(white) graphregion(color(white)) plotregion(lcolor(black) lwidth(medthin)) xlabel(,grid nogextend gmax) ytitle("Annual hours") ylabel(,grid nogextend) ysize(4) scheme(s1mono)
if `save_figures_flag'==1 {
	graph export "../figures/atus_male_bw.png", as(png) replace
	graph export "../figures/atus_male_bw.eps", as(eps) replace
}


twoway (connected by_sex_work by_sex_totalwork by_sex_leisure_broad year if male==0,/*
*/lpattern(solid dash dash_dot shortdash solid longdash solid solid) /*
*/msymbol(x o s p s p x o) msize(large medium small)), /*
*/leg(off) xlabel(1960[10]2020) ylabel(780[520]3380) xtitle("")/*
*/bgcolor(white) graphregion(color(white)) plotregion(lcolor(black) lwidth(medthin)) xlabel(,grid nogextend gmax) ytitle("Annual hours") ylabel(,grid nogextend) ysize(4)
if `save_figures_flag'==1 {
	graph export "../figures/atus_female.png", as(png) replace
	graph export "../figures/atus_female.eps", as(eps) replace
}
*black and white
twoway (connected by_sex_work by_sex_totalwork by_sex_leisure_broad year if male==0,/*
*/lpattern(solid dash dash_dot shortdash solid longdash solid solid) /*
*/msymbol(x o s p s p x o) msize(large medium small)), /*
*/leg(off) xlabel(1960[10]2020) ylabel(780[520]3380) xtitle("")/*
*/bgcolor(white) graphregion(color(white)) plotregion(lcolor(black) lwidth(medthin)) xlabel(,grid nogextend gmax) ytitle("Annual hours") ylabel(,grid nogextend) ysize(4) scheme(s1mono)
if `save_figures_flag'==1 {
	graph export "../figures/atus_female_bw.png", as(png) replace
	graph export "../figures/atus_female_bw.eps", as(eps) replace
}






